import pytest

from config import BASE_URL
from page.page_login import LoginPage
from script import log
from tools import DriverTools, read_json, GetLog


class TestLogin(object):

    def setup_method(self):
        # 打开浏览器
        driver = DriverTools.get_driver()
        # 输入网址
        driver.get(BASE_URL + "/common/member/login")
        # 调用方法：输入用户名、密码、点击登录
        self.login_page = LoginPage(driver)

    def teardown_method(self):
        # 关闭浏览器
        DriverTools.quit_driver()

    arg_names = "phone,pwd,expect,img"

    @pytest.mark.parametrize(arg_names, read_json("login_data.json"))
    def test_login(self, phone, pwd, expect, img):
        # 调用方法
        self.login_page.login(phone, pwd)
        # 打印结果
        if phone == "13800000001":
            result = self.login_page.get_success_result()
        else:
            result = self.login_page.get_fail_result()
        # print(result)
        # 记录日志
        log.info(f'执行结果:{result}')
        # 断言结果
        assert expect in result
        self.login_page.get_shot(img)
